#include <iostream>
#include <list>

using std::cout;
using std::endl;
using std::list;

void test0()
{
    list<int> vec = {1, 2, 2, 2, 2, 4, 6, 8, 2, 3};
    //需求：将所有等于2的元素从list删除
    for(auto it = vec.begin(); it != vec.end(); ++it)
    {
        if(2 == *it)
        {
            //不能删除连续重复的元素
            it = vec.erase(it);
        }
    }

    for(auto &elem : vec)
    {
        cout << elem << "  ";
    }
    cout << endl;
}

void test()
{
    list<int> vec = {1, 2, 2, 2, 2, 4, 6, 8, 2, 3};
    //需求：将所有等于2的元素从list删除
    for(auto it = vec.begin(); it != vec.end(); )
    {
        if(2 == *it)
        {
            //不能删除连续重复的元素
            it = vec.erase(it);
        }
        else
        {
            ++it;
        }
    }

    for(auto &elem : vec)
    {
        cout << elem << "  ";
    }
    cout << endl;
}
int main(int argc, char *argv[])
{
    test();
    return 0;
}

